package com.wpre.blogsystem.controller;

import com.wpre.blogsystem.common.pojo.request.AddBlogParam;
import com.wpre.blogsystem.common.pojo.request.UpdateBlogParam;
import com.wpre.blogsystem.common.pojo.response.BlogInfoResponse;
import com.wpre.blogsystem.common.pojo.response.BlogInfoResponseSimple;
import com.wpre.blogsystem.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-12-04
 * Time: 14:35
 */
@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource(name = "blogServiceImpl")
    private BlogService blogService;//BlogService是接口,但是我们需要注入的是blogServiceImpl

    //展示博客列表
    @RequestMapping("/getList")
    public List<BlogInfoResponseSimple> getList() {
        log.info("获取博客列表");
        return blogService.getList();
    }


    //展示博客详情
    @RequestMapping("/getBlogDetail")
    //@NotNull注解,校验参数
    public BlogInfoResponse getBlogDetail(@NotNull Integer blogId) {
        log.info("获取博客详情");
        return blogService.getBlogDetail(blogId);
    }


    //添加博客
    @PostMapping("/add")
    public boolean addBlog(@Validated @RequestBody AddBlogParam param) {//使用json传输,添加RequestBody注解
        log.info("添加博客");

        return blogService.addBlog(param);
    }

    //修改博客
    @PostMapping("/update")
    public boolean updateBlog(@Validated @RequestBody UpdateBlogParam param) {
        log.info("更新博客");
        return blogService.updateBlog(param);
    }

    //修改博客
    @PostMapping("/delete")
    public boolean deleteBlog(@NotNull Integer blogId) {
        log.info("删除博客");
        return blogService.deleteBlog(blogId);
    }




}
